<template>
  <div class="config">
    <header class="page-header">
      系统管理
    </header>

    <el-form class="cof-form" ref="form" :model="config" label-width="80px">
      <el-form-item label="名称">
        <el-input v-model="config.name"></el-input>
      </el-form-item>
      <el-form-item :label="'运营内容'">
        <el-input v-model="config.content" placeholder="运营内容概述" type="textarea"></el-input>
      </el-form-item>
      <el-form-item label="地址">
        <el-input v-model="config.address"></el-input>
      </el-form-item>
      <el-form-item label="联系人1">
        <el-input v-model="config.connect_name_1"></el-input>
      </el-form-item>
      <el-form-item label="联系电话1">
        <el-input v-model="config.connect_phone_1"></el-input>
      </el-form-item>
      <el-form-item label="联系人2">
        <el-input v-model="config.connect_name_2"></el-input>
      </el-form-item>
      <el-form-item label="联系电话2">
        <el-input v-model="config.connect_phone_2"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">立即更新</el-button>
        <el-button type="danger" @click="logout">退出登录</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import http from "../http/index.js";
export default {
  name: "config",
  data() {
    return {
      config: {
        name: "",
        address: "",
        connect_name_1: "",
        connect_phone_1: "",
        connect_name_2: "",
        connect_phone_2: ""
      }
    };
  },
  methods: {
    getConfig() {
      var self = this;
      http("/api/config/config_detail", {}, res => {
        for (var i in self.config) {
          self.config[i] = res.object[i];
        }
      });
    },
    onSubmit() {
      var self = this;
      http("/api/config/set_config", this.config, res => {
        if (res.code === 0) {
          self.$message.success(res.message);
          self.getConfig();
        }
      });
    },
    logout() {
      var self = this;
      http("/api/logout", this.config, res => {
        if (res.code === 0) {
          self.$router.push('/')
        }
      });
    },
    handleAvatarSuccess() {

    },
    beforeAvatarUpload() {

    }
  },

  created() {
    this.getConfig();
  }
};
</script>

<style lang="scss">
.cof-form {
  width: 540px;
  margin: 20px auto;
}
.config{
  .img-container{
    display: flex;
  }
  .contents{
    input{
      margin-bottom: 10px;
    }
  }
  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 128px;
    height: 128px;
    line-height: 128px;
    text-align: center;
  }
  .avatar {
    width: 128px;
    height: 128px;
    display: block;
  }
}
</style>
